package com.qst.system.controller;

import com.qst.common.core.controller.BaseController;
import com.qst.common.core.domain.AjaxResult;
import com.qst.common.core.page.TableDataInfo;
import com.qst.system.domain.vo.FaceCheckVo;
import com.qst.system.service.IFaceCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/facecheck")
public class FaceCheckController extends BaseController {

    @Autowired
    private IFaceCheckService faceCheckService;

    /**
     * 查询人脸识别记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:facecheck:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaceCheckVo faceCheck){
        startPage();
        List<FaceCheckVo> faceCheckVos = faceCheckService.selectFaceCheckList(faceCheck);
        return getDataTable(faceCheckVos);
    }

    /**
     * 获取人脸识别记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:facecheck:query')")
    @GetMapping("/{id}")
    public AjaxResult getFaceCheck(@PathVariable Long id){
        FaceCheckVo faceCheckVo = faceCheckService.selectFaceCheckById(id);
        return AjaxResult.success(faceCheckVo);
    }

    /**
     * 新增人脸识别记录
     */

    @PreAuthorize("@ss.hasPermi('system:facecheck:add')")
    @PostMapping
    public AjaxResult add(@RequestBody FaceCheckVo faceCheck){
        int result = faceCheckService.insertFaceCheck(faceCheck);
        if(result > 0){
            return AjaxResult.success("添加成功");
        }else{
            return AjaxResult.error("添加失败");
        }
    }

    /**
     * 修改人脸识别记录
     */
    @PreAuthorize("@ss.hasPermi('system:facecheck:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody FaceCheckVo faceCheck){
        int result = faceCheckService.updateFaceCheck(faceCheck);
        if(result > 0){
            return AjaxResult.success("修改成功");
        }else{
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除人脸识别记录
     */
    @PreAuthorize("@ss.hasPermi('system:facecheck:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        if (ids.length == 1){
            return toAjax(faceCheckService.deleteFaceCheckById(ids[0]));
        }
        return toAjax(faceCheckService.deleteFaceCheckByIds(ids));
    }

}